#include "debug.h"
#include "Utils\\ScreenFactory.h"

NS_BEGIN(SDL)
NS_BEGIN(UTILS)

ScreenFactory& ScreenFactory::m_instance = ScreenFactory();

#pragma region CTOR & DTOR

ScreenFactory::ScreenFactory()
{
	CTOR("ScreenFactory", this);
}

ScreenFactory::ScreenFactory(ScreenFactory const&)
{
}

ScreenFactory::~ScreenFactory()
{
	DTOR("ScreenFactory", this);
}

#pragma endregion
#pragma region Operators

ScreenFactory& ScreenFactory::operator=(ScreenFactory const&)
{
	return (*this);
}

ScreenFactory::ScreenCreator ScreenFactory::operator[](std::string const& _name)
{
	std::map<std::string, ScreenCreator>::iterator it =
		m_creators.find(_name);
	if (it == m_creators.end())
		return (NULL);
	return (it->second);
}

#pragma endregion

ScreenFactory& ScreenFactory::Instance()
{
	return (ScreenFactory::m_instance);
}

bool ScreenFactory::AddCreator(std::string const& _name,
							   ScreenFactory::ScreenCreator _screenCreator)
{
	if (m_creators.find(_name) != m_creators.end())
		return (false);
	m_creators[_name] = _screenCreator;
	return (true);
}

bool ScreenFactory::RemoveCreator(std::string const& _name)
{
	std::map<std::string, ScreenCreator>::iterator it = m_creators.find(_name);
	if (it == m_creators.end())
		return (false);
	m_creators.erase(it);
	return (true);
}

void ScreenFactory::ClearCreators()
{
	m_creators.clear();
}

IScreen* ScreenFactory::Create(std::string const& _name, IArgs* _args)
{
	if (m_creators.find(_name) == m_creators.end())
		return (false);
	return (m_creators[_name](_args));
}

#pragma region Getters & Setters

std::map<std::string, ScreenFactory::ScreenCreator> const&
													ScreenFactory::GetCreators() const
{
	return (m_creators);
}

#pragma endregion

NS_END(UTILS)
NS_END(SDL)